﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;
using MvcApplication1.Services;

namespace MvcApplication1.Controllers
{
    public class AttacksController : ApplicationController
    {

        /// <summary>
        /// render Hidden Form Attack page
        /// </summary>
        /// <returns>view</returns>
        public ActionResult HiddenForm()
        {
            ViewData["price"] = "*";

            return View();
        }
        
        /// <summary>
        /// Get value from the hidden form
        /// </summary>
        /// <returns>partial view</returns>
        public ActionResult HiddenFormAttack()
        {
            int value = 0;
            Int32.TryParse(Request.Form["hidden_val"], out value);
            ViewData["price"] = value;

            return PartialView("HiddenFormResult");
        }

        /// <summary>
        /// render SQL Injection attack page
        /// </summary>
        /// <returns>view</returns>
        public ActionResult SQLInjection()
        {
            ViewData["model"] = "false";
            return View();
        }

        /// <summary>
        /// Get reture value from the database
        /// </summary>
        /// <returns>partial view</returns>
        public ActionResult SQLInjectionAttack()
        {
            string username = "";
            string password = "";
            ViewData["msg"] = "";

            List<get_dummy_userResult> instance = new List<get_dummy_userResult>();

            try
            {
                username = Request.Form["username"];
                password = Request.Form["password"];

                if (username == "' OR 1=1 --")
                    username = "*";
                if (username == "' DROP TABLE USER_TABLE --")
                {
                    ViewData["msg"] = "Table USER_TABLE is deleted from database";
                    return PartialView("SQLInjectionResult");
                }

                instance = AttackRepository.GetDummyUser(username, password);
            }
            catch (Exception ex)
            {
                
            }
            ViewData["model"] = "true";

            return PartialView("SQLInjectionResult", instance);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult StatePoison()
        {
            return View();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult SessionHijack()
        {
            return View();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult XSS() 
        {
            return View();
        }
    }
}
